package com.samphanie.ane.core.security.handler;

import cn.hutool.json.JSONUtil;
import com.samphanie.ane.common.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author ZSY
 * @createTime 2021/3/13 17:37
 */
@Slf4j
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) throws IOException, ServletException {

        response.setStatus(HttpStatus.OK.value());
        response.getWriter().println(
                JSONUtil.toJsonStr(CommonResult.success("认证成功", auth))
        );
        log.debug("认证成功");

    }
}
